
#include "include.h"
#include "payload.h"


static const ELFLoaderSymbol_t exports[] = {
    { "puts", (void*) puts },
    { "printf", (void*) printf },
};
static const ELFLoaderEnv_t env = { exports, sizeof(exports) / sizeof(*exports) };

int main()
{ 
    ELFLoaderContext_t* ctx = elfLoaderInitLoadAndRelocate(example_payload_payload_elf, &env);
    if (!ctx) {
        printf("elfLoaderInitLoadAndRelocate error");
        return -1;
    }
    printf("load ok\n");
    if (elfLoaderSetFunc(ctx, "main") != 0) {
        printf("elfLoaderSetFunc error: main function not fount");
        elfLoaderFree(ctx);
        return -1;
    }
    printf("Running local_main(0x10) function as int local_main(int arg)");
    int r = elfLoaderRun(ctx, 0x10);
    printf("Result: %i", r);
    elfLoaderFree(ctx);

    printf("Done!\n"); 
  while(1);
  return 0;
}
